<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<!-- 引入 layui.css -->
		<link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css"/>
		<!-- 引入 layui.js -->
		<script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
		<script src="js/jquery-3.4.1.min.js"></script>
	</head>
	<body>
		<div class="layui-container">  
		  <div class="layui-row">
			<div class="layui-col-lg-offset3 layui-col-lg6 ">
				<div style="margin-top: 20px;">
					<form class="layui-form" action="">
					  <div class="layui-form-item">
					    <label class="layui-form-label">名称：</label>
					    <div class="layui-input-block">
					      <input type="text" name="name" required  lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
					    </div>
					  </div>
					  <div class="layui-form-item">
					    <label class="layui-form-label">密码：</label>
					    <div class="layui-input-block">
					      <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
					    </div>
					  </div>
					  <div class="layui-form-item">
					    <label class="layui-form-label">状态：</label>
					    <div class="layui-input-block">
					      <select name="flag" lay-verify="required">
					        <option value="1">有效</option>
					        <option value="2">无效</option>
					       
					      </select>
					    </div>
					  </div>
					  
					  <div class="layui-form-item">
					    <div class="layui-input-block">
					      <button class="layui-btn" lay-submit lay-filter="formDemo">新增用户</button>
					      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
					    </div>
					  </div>
					</form>
				</div>
			</div>
		</div>
		<script>
		//Demo
		layui.use('form', function(){
		  var form = layui.form;
		  
		  //监听提交
		  form.on('submit(formDemo)', function(data){
		    layer.msg(JSON.stringify(data.field));
			//请求后端接口
			$.ajax({
				type:"post",
				url:"/api/user/save.do",
				data:data.field,
				success:function(res){
					if(res.code==200){
						location.href="list.html";
					}else{
						layer.msg(res.msg);
					}
				}
			})
		    return false;
		  });
		});
		</script>
	</body>
	
</html>
